<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Insert title here</title>
	</head>
	<e:View id="view">
	    <script type="text/javascript">SkinUtil.getSkin();</script>
	    <script type="text/javascript">SkinUtil.getModuleSkin();</script>
	    
		<div id="Invisual Controls" style="min-height: 40px; background-color: LemonChiffon;" >
			<e:Dataset id="Dataset_FlowNode" datasetDefinition="DatasetDefinition_sys.dsd" datasetRef="Dataset_FlowNode" pageSize="-1" onAfterScroll="Dataset_FlowNode_onAfterScroll(dataset)">
				 <e:Field name="sortNo" dataType="integer" label="排序号" maxLength="2" required="true"/>
				 <e:Field name="nodeId" dataType="string" label="节点ID" maxLength="32" visible="false"/>
				 <e:Field name="nodeName" dataType="string" label="节点名称" maxLength="100" required="true"/>
				 <e:Field name="nodeUrl" dataType="string" label="节点URL" maxLength="200" />
				 <e:Field name="nodeType" dataType="string" label="节点类型" maxLength="1" required="true" dropDown="ListDropDown_NodeType"/>
				 <e:Field name="templateId" dataType="string" label="模板ID" maxLength="32" visible="false"/>
				 <e:Field name="teamId" dataType="string" label="节点操作人分组" maxLength="32" dropDown="ListDropDown_FlowTeam"/>
				 <e:Field name="teamLauncher" dataType="string" label="节点操作人与启动人关系" maxLength="1" dropDown="ListDropDown_TeamLauncher"/>
				 <e:Field name="handleMode" dataType="string" label="处理模式" maxLength="1" required="true" dropDown="ListDropDown_HandleMode"/>
				 <e:Field name="remark" dataType="string" label="备注" maxLength="200" />
			</e:Dataset>
			<e:Dataset id="Dataset_FlowRoute" datasetDefinition="DatasetDefinition_sys.dsd" datasetRef="Dataset_FlowRoute" pageSize="-1" onAfterScroll="Dataset_FlowRoute_onAfterScroll(dataset)">
				<e:Field name="routeId" dataType="string" label="路由ID" maxLength="32" visible="false"/>
				 <e:Field name="nodeId" dataType="string" label="当前节点" maxLength="32" required="true" dropDown="ListDropDown_FlowNode"/>
				 <e:Field name="routeCondition" dataType="string" label="条件表达式" maxLength="200" />
				 <e:Field name="nextNodeId" dataType="string" label="下一结点" maxLength="32" required="true" dropDown="ListDropDown_FlowNode"/>
				 <e:Field name="remark" dataType="string" label="备注" maxLength="200" />
			</e:Dataset>
			<e:Dataset id="Dataset_FlowParam" datasetDefinition="DatasetDefinition_sys.dsd" datasetRef="Dataset_FlowParam" pageSize="-1">
				<e:Field name="paramId" dataType="string" label="参数ID" maxLength="32" visible="false"/>
				 <e:Field name="routeId" dataType="string" label="路由ID" maxLength="32" visible="false"/>
				 <e:Field name="paramName" dataType="string" label="参数名称" maxLength="100" required="true"/>
				 <e:Field name="dataType" dataType="string" label="参数数据类型" maxLength="1" required="true" dropDown="ListDropDown_DataType"/>
				 <e:Field name="remark" dataType="string" label="备注" maxLength="200" />
			</e:Dataset>
			<e:Dataset id="Dataset_FlowTeam" datasetDefinition="DatasetDefinition_sys.dsd" datasetRef="Dataset_FlowTeam" pageSize="-1">
				<e:Field name="teamId" dataType="string" label="用户分组ID" maxLength="32" />
				 <e:Field name="teamName" dataType="string" label="分组名称" maxLength="100" />
				 <e:Field name="userNameList" dataType="string" label="分组成员用户名" maxLength="1000" />
				 <e:Field name="userIdList" dataType="string" label="分组成员用户ID" maxLength="1000" />
				 <e:Field name="remark" dataType="string" label="备注" maxLength="200" />
			</e:Dataset>
			
			<e:Command id="Command_SaveFlowNode" action="com.longtop.framework.sys.flow.web.FlowNodeListAction" method="saveFlowNode" submitForm="true" validateRequired="true">
				<e:DatasetInfo name="DatasetInfo1" dataset="Dataset_FlowNode" alwayRefreshClient="true" submitType="all"></e:DatasetInfo>
			</e:Command>
			<e:Command id="Command_SaveFlowRoute" action="com.longtop.framework.sys.flow.web.FlowNodeListAction" method="saveFlowRoute" submitForm="true" validateRequired="true">
				<e:DatasetInfo name="DatasetInfo2" dataset="Dataset_FlowRoute" alwayRefreshClient="true" submitType="all"></e:DatasetInfo>
			</e:Command>
			<e:Command id="Command_SaveFlowParam" action="com.longtop.framework.sys.flow.web.FlowNodeListAction" method="saveFlowParam" submitForm="true" validateRequired="true">
				<e:DatasetInfo name="DatasetInfo3" dataset="Dataset_FlowParam" alwayRefreshClient="true" submitType="all"></e:DatasetInfo>
			</e:Command>
			
			<e:Command id="Command_LoadFlowRoute" action="com.longtop.framework.sys.flow.web.FlowNodeListAction" method="loadFlowRoute" submitForm="true" submitFormScope="all" validateRequired="true" >
				<e:DatasetInfo name="DatasetInfo4" dataset="Dataset_FlowRoute" alwayRefreshClient="true" ></e:DatasetInfo>
			</e:Command>
			<e:Command id="Command_LoadFlowParam" action="com.longtop.framework.sys.flow.web.FlowNodeListAction" method="loadFlowParam" submitForm="true" submitFormScope="all" validateRequired="true">
				<e:DatasetInfo name="DatasetInfo5" dataset="Dataset_FlowParam" alwayRefreshClient="true" submitType="all"></e:DatasetInfo>
			</e:Command>
			
			<e:DataDropDown id="ListDropDown_FlowNode" dataset="Dataset_FlowNode" visibleFields="sortNo,nodeName"
					writeFields="" codeField="nodeId" textField="nodeName" fixed="true">
			</e:DataDropDown>
			<e:DataDropDown id="ListDropDown_FlowTeam" dataset="Dataset_FlowTeam" visibleFields="teamId,teamName"
					writeFields="" codeField="teamId" textField="teamName" fixed="false">
			</e:DataDropDown>
			
			<e:ListDropDown id="ListDropDown_NodeType" autoDropDown="true" fixed="true">
				<e:ListDropDownItem name="ListDropDownItem1" label="启动节点" value="1"></e:ListDropDownItem>
				<e:ListDropDownItem name="ListDropDownItem8" label="被驳回到启动节点" value="8"></e:ListDropDownItem>
				<e:ListDropDownItem name="ListDropDownItem2" label="一般节点" value="2"></e:ListDropDownItem>
				<e:ListDropDownItem name="ListDropDownItem9" label="结束节点" value="9"></e:ListDropDownItem>
			</e:ListDropDown>
			<e:ListDropDown id="ListDropDown_HandleMode" autoDropDown="true" fixed="true">
				<e:ListDropDownItem name="ListDropDownItem1" label="抢占式" value="1"></e:ListDropDownItem>
				<e:ListDropDownItem name="ListDropDownItem2" label="协同式" value="2"></e:ListDropDownItem>
			</e:ListDropDown>
			<e:ListDropDown id="ListDropDown_DataType" autoDropDown="true" fixed="true">
				<e:ListDropDownItem name="ListDropDownItem1" label="字符串型" value="1"></e:ListDropDownItem>
				<e:ListDropDownItem name="ListDropDownItem2" label="整数型" value="2"></e:ListDropDownItem>
				<e:ListDropDownItem name="ListDropDownItem3" label="布尔型" value="3"></e:ListDropDownItem>
			</e:ListDropDown>
			<e:ListDropDown id="ListDropDown_TeamLauncher" autoDropDown="true" fixed="true">
				<e:ListDropDownItem name="ListDropDownItem0" label="" value=""></e:ListDropDownItem>
				<e:ListDropDownItem name="ListDropDownItem1" label="与启动人同机构" value="1"></e:ListDropDownItem>
			</e:ListDropDown>
		</div>
	
		<body>
			<e:Page id="ePage" action="com.longtop.framework.sys.flow.web.FlowNodeListAction" style="min-height: 80px; width: 100%; height: 100%;" onAfterLoadPage="ePage_onAfterLoadPage()">
				<table style="width: 100%; height: 100%;" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
					<tr>
						<td valign="top" width="60%">
							<e:Panel id="Panel1" style="width: 100%; height: 100%" captionStyle="color:#888888" caption="流程模板节点列表" captionIcon="/images/list_win.gif">
								<table style="text-align: left; width: 100%;" border="0" cellpadding="3" cellspacing="3" >
									<tr>
										<td>
											<table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
												<tr>
													<td height="27px" width="1%">
														<e:RecordNavigator id="RecordNavigator_FlowNode" dataset="Dataset_FlowNode" showNavigatorButton="false">
															<e:RecordButton id="RecordButton_insert" label="新增" onClick="RecordButton_insertFlowNode_onClick()" icon="/images/add.gif"></e:RecordButton>
															<e:RecordButton id="RecordButton_delete" label="删除" onClick="deleteRecord" icon="/images/delete.gif"></e:RecordButton>
															<e:RecordButton id="RecordButton_save" label="保存" onClick="RecordButton_saveFlowNode_onClick()" icon="/images/submit.gif"></e:RecordButton>
														</e:RecordNavigator>
													</td>
													<td align="left" width="99%">&nbsp;</td>
												</tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<e:Grid id="Grid_FlowNode" style="width: 100%; height: 420px;" showIndex="false" dataset="Dataset_FlowNode" onClick="Grid_flowNode_onClick()">
											</e:Grid>
										</td>
									</tr>
								</table>
							</e:Panel>
						</td>
						<td valign="top" width="40%">
							<e:Panel id="Panel2" style="width: 100%; height: 50%" captionStyle="color:#888888" caption="节点路由列表" captionIcon="/images/list_win.gif">
								<table style="text-align: left; width: 100%;" border="0" cellpadding="3" cellspacing="3" >
									<tr>
										<td>
											<table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
												<tr>
													<td height="27px" width="1%">
														<e:RecordNavigator id="RecordNavigator_Route" dataset="Dataset_FlowRoute" showNavigatorButton="false">
															<e:RecordButton id="RecordButton_insert" label="新增" onClick="RecordButton_insertFlowRoute_onClick()" icon="/images/add.gif"></e:RecordButton>
															<e:RecordButton id="RecordButton_delete" label="删除" onClick="deleteRecord" icon="/images/delete.gif"></e:RecordButton>
															<e:RecordButton id="RecordButton_save" label="保存" onClick="RecordButton_saveFlowRoute_onClick()" icon="/images/submit.gif"></e:RecordButton>
														</e:RecordNavigator>
													</td>
													<td align="left" width="99%">&nbsp;</td>
												</tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<e:Grid id="Grid_FlowRoute" style="width: 96%; height: 160px;" showIndex="false" dataset="Dataset_FlowRoute" onClick="Grid_FlowRoute_onClick()">
											</e:Grid>
										</td>
									</tr>
								</table>
							</e:Panel>
							<e:Panel id="Panel3" style="width: 100%; height: 50%" captionStyle="color:#888888" caption="路由参数列表" captionIcon="/images/list_win.gif">
								<table style="text-align: left; width: 100%;" border="0" cellpadding="3" cellspacing="3" >
									<tr>
										<td>
											<table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
												<tr>
													<td height="27px" width="1%">
														<e:RecordNavigator id="RecordNavigator_FlowParam" dataset="Dataset_FlowParam" showNavigatorButton="false">
															<e:RecordButton id="RecordButton_insert" label="新增" onClick="RecordButton_insertFlowParam_onClick()" icon="/images/add.gif"></e:RecordButton>
															<e:RecordButton id="RecordButton_delete" label="删除" onClick="deleteRecord" icon="/images/delete.gif"></e:RecordButton>
															<e:RecordButton id="RecordButton_save" label="保存" onClick="RecordButton_saveFlowParam_onClick()" icon="/images/submit.gif"></e:RecordButton>
														</e:RecordNavigator>
													</td>
													<td align="left" width="99%">&nbsp;</td>
												</tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<e:Grid id="Grid_FlowParam" style="width: 96%; height: 160px;" showIndex="false" dataset="Dataset_FlowParam" >
											</e:Grid>
										</td>
									</tr>
								</table>
							</e:Panel>
						</td>
					</tr>
			    </table>
			</e:Page>
		</body>
	</e:View>
</html>
<script type="text/javascript">
	var allowSearch = false;
	//init
	function ePage_onAfterLoadPage(){
		allowSearch = true;
		$J("Dataset_FlowNode").onAfterScroll();
		$J("Dataset_FlowRoute").onAfterScroll();
	}
	
	//新增节点
	function RecordButton_insertFlowNode_onClick(){
		var dataset_FlowNode = $J("Dataset_FlowNode");	
		var panel1 = $J("Panel1");
			
		var templateId = panel1.tag;
		
		var nodeRecord = dataset_FlowNode.insertRecord();
		if(nodeRecord==null){
			return;
		}
		nodeRecord.setValue("templateId", templateId);
	}

	//保存节点
	function RecordButton_saveFlowNode_onClick(){
	    Command_SaveFlowNode.execute();
	}
	
	//新增路由
	function RecordButton_insertFlowRoute_onClick(){
		var panel1 = $J("Panel1");
		var templateId = panel1.tag;
		
		var dataset_FlowNode = $J("Dataset_FlowNode");
		var dataset_FlowRoute = $J("Dataset_FlowRoute");
		var flowNodeId = dataset_FlowNode.getValue("nodeId");
		
		if (!flowNodeId){
			alert('请先选择一条节点记录。');
			return ;
		}
		
		var routeRecord = dataset_FlowRoute.insertRecord();
		if(routeRecord==null){
			return;
		}
		routeRecord.setValue("nodeId", flowNodeId);
		routeRecord.setValue("templateId", templateId);
	}
	
	//保存路由
	function RecordButton_saveFlowRoute_onClick(){
		Command_SaveFlowRoute.execute();
	}

	//新增路由参数
	function RecordButton_insertFlowParam_onClick(){
		var dataset_FlowParam = $J("Dataset_FlowParam");
		var record_FlowRoute = $J("Dataset_FlowRoute").getCurrentRecord();
		
		var routeId = record_FlowRoute.getValue("routeId");
		if (!routeId){
			alert('请先选择一条路由记录。');
			return ;
		}
		var paramRecord = dataset_FlowParam.insertRecord();
		if(paramRecord==null){
			return;
		}
		paramRecord.setValue("routeId", routeId);
	}
	
	//保存路由参数信息
	function RecordButton_saveFlowParam_onClick(){
		Command_SaveFlowParam.execute();
	}
	
	//选择不同节点，触发查询该节点的路由
	function Dataset_FlowNode_onAfterScroll(dataset){
		if(!allowSearch) 
			return;
			
		//取得当前节点的 nodeId，提交查询
		var record_FlowNode = $J("Dataset_FlowNode").getCurrentRecord();
		if(record_FlowNode == null){
			return;
		}
		var flowNodeId = record_FlowNode.getValue("nodeId");
		$J("Command_LoadFlowRoute").parameters.setValue("flowNodeId", flowNodeId);	//command传参
		Command_LoadFlowRoute.execute();
	}
	
	//选择不同路由，触发查询该路由的参数
	function Dataset_FlowRoute_onAfterScroll(dataset){
		//取得当前路由的 routeId，提交查询
		var record_FlowRoute = $J("Dataset_FlowRoute").getCurrentRecord();
		if(record_FlowRoute == null){
			return;
		}		
		var flowRouteId = record_FlowRoute.getValue("routeId");
		$J("Command_LoadFlowParam").parameters.setValue("flowRouteId", flowRouteId);	//command传参
		Command_LoadFlowParam.execute();
	}
</script>